import { api } from '@/api/request'
import type { PageData, PageQuery } from '@/types'

// 用户查询参数
export interface UserQuery extends PageQuery {
  username?: string
  email?: string
  family_id?: number
}

// 用户信息
export interface UserInfo {
  id: number
  username: string
  email: string
  nickname?: string
  avatar?: string
  is_active: boolean
  is_superuser: boolean
  created_at: string
  updated_at: string
}

// 创建用户请求
export interface CreateUserRequest {
  id : number
  username: string
  email: string
  nickname?: string
  password: string
}

// 更新用户请求
export interface UpdateUserRequest {
  id : number
  email?: string
  nickname?: string
  is_active?: boolean
}

// 用户管理相关 API
export const userApi = {
  // 获取用户列表
  getUserList: (params: UserQuery) => 
    api.get<PageData<UserInfo>>('/user/list', { params }),
  
  // 获取用户详情
  getUser: (userId: number) => 
    api.get<UserInfo>(`/user/${userId}`),
  
  // 创建用户
  createUser: (data: CreateUserRequest) => 
    api.post<UserInfo>('/user/create', data),
  
  // 更新用户
  updateUser: (userId: number, data: UpdateUserRequest) => 
    api.put<UserInfo>(`/user/${userId}`, data),
  
  // 删除用户
  deleteUser: (userId: number) => 
    api.delete(`/user/${userId}`),
  
  // 重置用户密码
  resetPassword: (userId: number) => 
    api.post(`/user/${userId}/reset-password`),
}